<?php

namespace app\api\model\user;

use app\api\model\Models;
use think\db\Query;

class User extends Models
{
    /**
     * 定义时间戳字段名
     * @var string
     */
    protected $createTime = 'create_at';

    /**
     * 定义时间戳字段名
     * @var string
     */
    protected $updateTime = 'update_at';

    /**
     * 设置时间戳格式
     * @var string
     */
    protected $autoWriteTimestamp = 'datetime';

    /**
     * 设置用户unionid查询
     * @param Query $query
     * @param string|NULL $unionid
     * @return void
     */
    public function scopeUnionid( Query $query, string $unionid )
    {
        $query->where('unionid', $unionid);
    }

    /**
     * 设置用户openid查询
     * @param Query $query
     * @param array $data
     * @return void
     */
    public function scopeOpenid( Query $query, array $data )
    {
        $query->where($data['field'], $data['openid']);
    }

}
